package Presenter;

import java.util.ArrayList;

import org.json.JSONException;
import org.json.JSONObject;

import Models.MashNotes;

public class MashNotesPresenter extends AbstractPresenter<MashNotes> {
	final String SINGLEITEM = "mashNotes";
	final String MULTIITEM = "mashNotess";
	
	public ArrayList<MashNotes> tryJSONParseArray(String input){
		return super.doJSONParseArray(input, SINGLEITEM, MULTIITEM);
	}
	
	public MashNotes tryJSONParse(String input){
		return super.doJSONParse(input, SINGLEITEM);
	}
	
	public MashNotes createItemFromJSONObject(JSONObject jsonObject){
		MashNotes item = new MashNotes();
		try{
			item.setId(jsonObject.getInt("noteID"));
			item.setMashType(jsonObject.getInt("mashType"));
			item.setNotes(jsonObject.getString("notes"));
			item.setTemp(jsonObject.getDouble("temp"));
			item.setTime(timeFormat.parse(jsonObject.getString("stopTime")));
			
			return item;
		} catch(JSONException ex){
			ex.printStackTrace();
		} catch(Exception ex){
			ex.printStackTrace();
		}
		return null;
	}
	
	public JSONObject createJSON(MashNotes item){
		try{
			JSONObject json = new JSONObject();
			json.put("noteID", item.getId());
			json.put("mashType", item.getMashType());
			json.put("notes", item.getNotes());
			json.put("temp", item.getTemp());
			json.put("stopTime", getDate(item.getTime()));
			
			return json;
		} catch(JSONException ex){
			ex.printStackTrace();
		}
		return null;
	}
	
	public MashNotes getEmptyEntity(){
		MashNotes entity = new MashNotes();
		return entity;
	}
}
